#ifndef SWARMSOCKETCLIENT_H
#define SWARMSOCKETCLIENT_H
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <cstring>
#include <iostream>
//#include "socketTest.h"
//! client socket sends messages to a listening server
class swarmSocketClient {
	private:
	//! the port number and the socket
	int port, sock;
	//! name of the server host
	char* serverHost;
	//! sets of socket fields
	fd_set active_fd_set, read_fd_set;
	//! struct to hold the servername
	struct sockaddr_in servername;
	//! struct to hold timeout value
	struct timeval tv;
	public:
	/*! a constructor which initialized port and serverHost
	 * \param hst initializes serverHost
	 * \param pt initializes port
	 */
	swarmSocketClient(const char* hst, int pt);
	//! a default constructor which assumes the user will initialize port and serverHost later
	swarmSocketClient();
	/*! initializes the socket connection
	 * \return 0 if connection was successful, less than 0 if otherwise
	 */
	int initclient();
	/*! initializes the socket connection
	 * \param hst initializes serverHost
	 * \param pt initializes port
	 * \return 0 if connection was successful, less than 0 if otherwise
	 */
	int initclient(const char* hst, int pt);
	//! closes the socket connection
	void shut();
	/*! writes a message to a listening server
	 * \param message is the message
	 * \param size is the number of bytes in the message
	 * \return 0 if the write was successful, less than 0 if otherwise
	 */
	int writeMessage(const void* message, int size);
	//! \return true if still connected false otherwise
	bool checkConnection();
	//! desctructor closes socket connection
	~swarmSocketClient();
};
#endif
